package cn.wolfcode.cms.web.controller;

import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IPermissionService;
import cn.wolfcode.cms.util.JSONResult;
import cn.wolfcode.cms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("")
    public String main(){
        return "permission/list";
    }

    @RequestMapping("/list")
    @ResponseBody
    public Object list(QueryObject qo){
        PageResult result = permissionService.query(qo);
        return result;
    }
    @RequestMapping("getPermissionByRoleId")
    @ResponseBody
    public Object getPermissionByRoleId(Long id){
        return permissionService.getPermissionByRoleId(id);
    }

    //查询所有数据满足datagrid不带分页
    @RequestMapping("/listData")
    @ResponseBody
    public Object listData(){
        return permissionService.list();
    }


    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        JSONResult result = new JSONResult();
        try {
            permissionService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    @RequestMapping("/reload")
    @ResponseBody
    public Object reload(){
        JSONResult result = new JSONResult();
        try {
            permissionService.reload();
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
